<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>    
    var lever = prompt('请设置金字塔层数');
    lever = parseFloat(lever) && Number(lever);
    if(isNaN(lever)){
        alert('金字塔的层数必须为纯数字');
    }
    for(var i=1;i<=lever;++i){
        var blank =lever - i;
        for(var k=0;k<blank;++k){
            document.write('&nbsp');
        }
        var star = i*2 -1;
        for(var j=0;j<star;++j){
            document.write('*');
        }
        document.write('</br>');
    }
    </script>
</body>
</html>